package com.woniuxy.creditsystem.common.mapper;


import com.woniuxy.creditsystem.common.bean.RoleInfo;
import com.woniuxy.creditsystem.common.bean.UserInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 用户的增、删、查、改
 * @author hejie
 */
@Mapper
public interface RoleMenuMapper {


    /**
     * 新增管理员
     * @param roleId 当前的角色
     * @param menuId 该角色能看到的其中一个菜单
     * @return 受影响的行数
     */
//    @Options(
//            useGeneratedKeys = true,
//            keyProperty = "id"
//    )
    @Insert("insert into role_menu_info " +
            "(fk_role_id,fk_menu_id,opt_perm)" +
            " values(#{roleId},#{menuId},'')" )
    int saveRoleMenuBean(@Param("roleId") Long roleId ,@Param("menuId") Long menuId);


    /**
     * 修改用户--------有空在test条件中加上“xxx！=‘’”
     * @param userInfo
     * @return 受影响的行数
     */
   /* @Update("<script>" +
            "update user_info" +
            "<set>" +
            "<if test='a.userName != null'>" +
            " user_name = #{a.userName}," +
            "</if>" +
            "<if test='a.password != null'>" +
            " password = #{a.password}," +
            "</if>" +
            "<if test='a.roleInfo != null and a.roleInfo.id != null'>" +
            " fk_role_id = #{a.roleInfo.id}," +
            "</if>" +
            "<if test='a.job != null'>" +
            " job = #{a.job}," +
            "</if>" +
            "<if test='a.status != null'>" +
            " status = #{a.status}," +
            "</if>" +
            "modify_time=now()"+
            "</set>" +
            "where id = #{a.id}" +
            "</script>")
    int updateUserBean(@Param("a") UserInfo userInfo);*/
    /**
     * 删除管理员
     * @param roleId 角色的id
     * @param menuId 菜单的id
     * @return 受影响的行数
     */

   @Delete("delete from role_menu_info where fk_role_id = #{roleId} and fk_menu_id = #{menuId}")
    int deleteRoleMenu(@Param("roleId")Long roleId, @Param("menuId")Long menuId);

    /**
     * 分页查询
     * @param userInfo
     * @return
     */
    /*List<UserInfo> findAllByParams(@Param("a") UserInfo userInfo);*/


    /**
     * 根据ID查询用户
     * @param id
     * @return
     */

 /*  @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "userName",column = "user_name",javaType = String.class),
            @Result(property = "password",column = "password",javaType = String.class),
            @Result(property = "status",column = "status",javaType = Integer.class),
            @Result(property = "job",column = "job",javaType = String.class),
//            @Result(property = "telephone",column = "telephone",javaType = String.class),
//            @Result(property = "createTime",column = "create_time",javaType = Date.class),
//            @Result(property = "modifyTime",column = "modify_time",javaType = Date.class),
//            @Result(property = "delFlag",column = "del_flag",javaType = Integer.class),
            @Result(property = "roleInfo",column = "fk_role_id",javaType = RoleInfo.class,one =
            @One(select = "com.woniuxy.creditsystem.systemmag.mapper.RoleMapper.getOneById",fetchType = FetchType.EAGER))
    })
    @Select("select * from user_info where id = #{id}")
   UserInfo getOneById(Long id);

   @Select("select user_name as userName from  user_info where id = #{id}")
   UserInfo getNameById(Long id);*/
}
